package com.building.controller;

import com.building.common.R;
import com.building.controller.BaseController.BaseController;
import com.building.entity.Engineering;
import com.building.enums.REnum;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 项目工程信息控制器
 *
 * @author yinjiahui
 * @create 2021-04-07 19:28
 */
@RestController
@RequestMapping("engineering")
@Api(tags = "项目工程信息控制器")
public class EngineeringController extends BaseController {

    /**
     * 查询所有数据  加 分页
     * @param limit
     * @param page
     * @return
     */
    @GetMapping("selectEngineering/{limit}/{page}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="分页第几页参数",name="limit",dataType="Integer",required=true,value="分页的第几页",defaultValue="这个是默认值，可以不写"),
            @ApiImplicitParam(paramType="分页每页条数参数",name="page",dataType="Integer",required=true,value="分页的每页条数",defaultValue="这个是默认值，可以不写")
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectEngineering(@PathVariable("limit") Integer limit, @PathVariable("page") Integer page){
        return R.result(REnum.SUCCESS_QUERY,this.engineeringService.selectEngineering(limit,page));
    }


    /**
     * 根据类别或者阶段进行条件查询
     * @param engineeringTypeId
     * @param engineeringStageId
     * @return
     */
    @GetMapping("selectEngineeringByEngineeringTypeIdOrEngineeringStageId/{engineeringTypeId}/{engineeringStageId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据类别条件查询",name="engineeringTypeId",dataType="Integer",required=true,value="那个类别",defaultValue="这个是默认值，可以不写"),
            @ApiImplicitParam(paramType="根据阶段条件查询",name="engineeringStageId",dataType="Integer",required=true,value="那个阶段",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectEngineeringByEngineeringTypeIdOrEngineeringStageId(@PathVariable("engineeringTypeId") Integer engineeringTypeId,@PathVariable("engineeringStageId") Integer engineeringStageId){
        return R.result(REnum.SUCCESS_QUERY,this.engineeringService.selectEngineeringByEngineeringTypeIdOrEngineeringStageId(engineeringTypeId,engineeringStageId));
    }

    /**
     * 根据项目工程编号查询这条数据       //回显
     * @param engineeringId
     * @return
     */
    @GetMapping("selectEngineeringByEngineeringId/{engineeringId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据工程编号id查询这条信息",name="engineeringId",dataType="Integer",required=true,value="项目工程编号",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectEngineeringByEngineeringId(@PathVariable("engineeringId") Integer engineeringId){
        return R.result(REnum.SUCCESS_QUERY,this.engineeringService.selectEngineeringByEngineeringId(engineeringId));
    }


    /**
     * 根据项目名称的关键字进行条件查询
     * @param engineeringName
     * @return
     */
    @GetMapping("selectEngineeringByEngineeringName/{engineeringName}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据项目名称的关键字进行条件查询",name="engineeringName",dataType="String",required=true,value="项目工程名称",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectEngineeringByEngineeringName(@PathVariable("engineeringName") String engineeringName){
        return R.result(REnum.SUCCESS_QUERY,this.engineeringService.selectEngineeringByEngineeringName(engineeringName));
    }

    /**
     * 新增或修改数据
     * @param engineering
     * @return
     */
    @PostMapping("insertOrUpdateEngineering")
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R insertOrUpdateEngineering(@RequestBody Engineering engineering){
        return this.engineeringService.insertOrUpdateEngineering(engineering);
    }

    /**
     * 根据根据工程编号id删除
     *
     * @param engineeringId
     * @return
     */
    @DeleteMapping("deleteEngineeringByEngineeringId/{engineeringId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据根据工程编号id删除",name="engineeringId",dataType="Integer",required=true,value="工程编号id",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R deleteEngineeringByEngineeringId(@PathVariable("engineeringId") Integer engineeringId){
        this.engineeringService.deleteEngineeringByEngineeringId(engineeringId);
        return R.result(REnum.SUCCESS_DELETE);
    }


}
